namespace Trust.Casas.Model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AppSetting",
                c => new
                    {
                        Key = c.String(nullable: false, maxLength: 100),
                        Value = c.String(maxLength: 1000),
                        Description = c.String(maxLength: 1000),
                        CreatedStamp = c.DateTime(nullable: false, precision: 7, storeType: "datetime2", defaultValueSql:"GETDATE()"),
                        UpdatedStamp = c.DateTime(precision: 7, storeType: "datetime2"),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Key);
            
            CreateTable(
                "dbo.BuildingType",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 200),
                        Description = c.String(maxLength: 200),
                        CreatedStamp = c.DateTime(nullable: false, precision: 7, storeType: "datetime2", defaultValueSql: "GETDATE()"),
                        UpdatedStamp = c.DateTime(precision: 7, storeType: "datetime2"),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Region",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 150),
                        Location = c.Geography(),
                        Space = c.Geometry(),
                        ParentRegionId = c.Int(),
                        CreatedStamp = c.DateTime(nullable: false, precision: 7, storeType: "datetime2", defaultValueSql: "GETDATE()"),
                        UpdatedStamp = c.DateTime(precision: 7, storeType: "datetime2"),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Region", t => t.ParentRegionId)
                .Index(t => t.ParentRegionId);
            
            CreateTable(
                "dbo.SearchType",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 150),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserDetail",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        FirstName = c.String(maxLength: 100),
                        LastName = c.String(maxLength: 100),
                        CreatedStamp = c.DateTime(nullable: false, precision: 7, storeType: "datetime2", defaultValueSql: "GETDATE()"),
                        UpdatedStamp = c.DateTime(precision: 7, storeType: "datetime2"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.User",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 150),
                        CreatedStamp = c.DateTime(nullable: false, precision: 7, storeType: "datetime2", defaultValueSql: "GETDATE()"),
                        UpdatedStamp = c.DateTime(precision: 7, storeType: "datetime2"),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserDetail", "UserId", "dbo.User");
            DropForeignKey("dbo.Region", "ParentRegionId", "dbo.Region");
            DropIndex("dbo.UserDetail", new[] { "UserId" });
            DropIndex("dbo.Region", new[] { "ParentRegionId" });
            DropTable("dbo.User");
            DropTable("dbo.UserDetail");
            DropTable("dbo.SearchType");
            DropTable("dbo.Region");
            DropTable("dbo.BuildingType");
            DropTable("dbo.AppSetting");
        }
    }
}
